<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>deepMerge</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const deepMerge = (a, b, handler) =>
            [...new Set([...Object.keys(a), ...Object.keys(b)])].reduce(
                (acc, key) => ({ ...acc, [key]: handler(key, a[key], b[key]) }),
                {}
            );
        console.log(deepMerge(
            { a: true, b: { c: [1, 2, 3] } },
            { a: false, b: { d: [1, 2, 3] } },
            (key, a, b) => (key === 'a' ? a && b : Object.assign({}, a, b))
        ));
    </script>
</body>

</html>